﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PanhuaWin.工厂
{
    public partial class Form小标签 : UIForm
    {

        public string 工厂编号;
        public string 来源种类;
        public string 生产日期;

        public string 生产批号;
        public string 规格;
        public string 钢号;
        public string 净重;
        public string 等级;
        public string 表面状态;
        public string 表面处理;
        public string 长度;
        public string 品名;
        public string 执行标准;
        public string 存货编号;
        public string 班组;
        public string 产线名称;
        public string 产线编号;
        public string 颜色;
        public string 包装;
        public string 仓库;
        public string 锌层;
        public string 客户;
        public string 抗拉;
        public string 屈服;
        public string 延伸率;
        public Form小标签()
        {
            InitializeComponent();
        }

        private void uiButton打印_Click(object sender, EventArgs e)
        {
            打印();
        }

        public void 打印()
        {
            //string 仓库 = 保存的仓库;
            string 仓库 = uiComboBox仓库编号.SelectedValue?.ToString();
            string 锌层 = uiTextBox锌层.Text;
            
            //if (string.IsNullOrEmpty(仓库))
            //{
            //    MessageBox.Show("请选择仓库");
            //    return;
            //}
            //if (string.IsNullOrEmpty(包装形式))
            //{
            //    MessageBox.Show("请选择包装形式");
            //    return;
            //}
            string sql;
            //if (存货编号 == "")
            //{
            //    if (MessageBox.Show("这个卷没有存货编号，也要打印么?", "询问", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            //    {
            //        return;
            //    }
            //}

            BarTender.Application ba = new BarTender.Application();
            BarTender.Format bfmt;
            bfmt = new BarTender.Format();
            switch (来源种类)
            {
                case "酸洗小标签":
                    bfmt = ba.Formats.Open(System.Windows.Forms.Application.StartupPath + "\\攀华酸洗小标签.btw");
                    break;
                case "轧硬小标签":
                    bfmt = ba.Formats.Open(System.Windows.Forms.Application.StartupPath + "\\攀华轧硬小标签.btw");
                    break;
                case "镀锌小标签":
                    bfmt = ba.Formats.Open(System.Windows.Forms.Application.StartupPath + "\\攀华镀锌小标签.btw");
                    break;
                case "彩涂小标签":
                    bfmt = ba.Formats.Open(System.Windows.Forms.Application.StartupPath + "\\攀华彩涂小标签.btw");
                    break;
                case "罩退小标签":
                    bfmt = ba.Formats.Open(System.Windows.Forms.Application.StartupPath + "\\攀华罩退小标签.btw");
                    break;
                case "退火小标签":
                    bfmt = ba.Formats.Open(System.Windows.Forms.Application.StartupPath + "\\攀华退火小标签.btw");
                    break;
                case "硅钢小标签":
                    bfmt = ba.Formats.Open(System.Windows.Forms.Application.StartupPath + "\\攀华硅钢小标签.btw");
                    break;
            }
            bfmt.SetNamedSubStringValue("生产批号", 生产批号);
            bfmt.SetNamedSubStringValue("品名", 品名);
            bfmt.SetNamedSubStringValue("钢号", 钢号);
            bfmt.SetNamedSubStringValue("长度", 长度);
            bfmt.SetNamedSubStringValue("规格", 规格);
            bfmt.SetNamedSubStringValue("等级", 等级);
            bfmt.SetNamedSubStringValue("表面状态", 表面状态);
            bfmt.SetNamedSubStringValue("表面处理", 表面处理);
            bfmt.SetNamedSubStringValue("净重", 净重);
            bfmt.SetNamedSubStringValue("备注", 执行标准);
            bfmt.SetNamedSubStringValue("生产日期", 生产日期);
            bfmt.SetNamedSubStringValue("班组", 班组);
            if (pub.全局仓库 != null)
            {
                仓库 = pub.全局仓库;
            }
            bfmt.SetNamedSubStringValue("仓库", 仓库);
            bfmt.PrintOut();
            sql = "delete Bus_LablePrint where 生产批号='" + 生产批号 + "'";
            pub.ExecuteSql(pub.ConnectionString, sql, "小标签打印前清理");
            sql = "insert into Bus_LablePrint(guid, 来源种类,来源产线,工厂编号, 生产批号,  品名, 钢号, 条码, 长度, 规格, 等级, 表面状态,  ";
            sql += " 表面处理, 净重, 备注, 生产日期,  操作ip, 操作人员, 操作时间 ,仓库,锌层,包装形式,班组,颜色,客户,抗拉,屈服,延伸率 ) ";
            sql += " values(newid(),'" + 来源种类 + "','" + 产线名称 + "','" + 工厂编号 + "','" + 生产批号 + "',";
            sql += " '" + 品名 + "','" + 钢号 + "','" + 生产批号 + "','" + 长度 + "','" + 规格 + "','" + 等级 + "','" + 表面状态 + "',";
            sql += " '" + 表面处理 + "','" + 净重 + "','" + 执行标准 + "','" + 生产日期 + "','" + pub.getMac() + "',";
            sql += " '" + pub.sys_user.UserTrueName + "',getdate(),'" + 仓库 + "','" + 锌层 + "','" + 包装 + "','" + 班组 + "','" + 颜色 + "','" + 客户 + "',";
            sql += " '" + 抗拉 + "','" + 屈服 +"','" + 延伸率  + "')";
            pub.ExecuteSql(pub.ConnectionString, sql, "小标签打印塞入");
            switch (来源种类)
            {
                case "酸洗小标签":
                    sql = "update  Bus_PicklingOutput set PrintTimes =PrintTimes+1 ";
                    sql += " where OutputVolumeNew='" + 生产批号 + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "酸洗小标签打印次数更新");
                    break;
                case "轧硬小标签":
                    sql = "update  Bus_HardOutput set  PrintTimes =PrintTimes+1 ";
                    sql += " where OutputVolumeNew='" + 生产批号 + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "轧硬小标签打印次数更新");
                    break;
                case "镀锌小标签":
                    sql = "update  Bus_ZincOutput set  PrintTimes =PrintTimes+1 ";
                    sql += " where OutputVolumeNew='" + 生产批号 + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "镀锌小标签打印次数更新");
                    break;
                case "彩涂小标签":
                    sql = "update  Bus_PaintOutput set  PrintTimes =PrintTimes+1 ";
                    sql += " where OutputVolumeNew='" + 生产批号 + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "彩涂小标签打印次数更新");
                    break;
                case "罩退小标签":
                    sql = "update  Bus_CoverFireOutput set  PrintTimes =PrintTimes+1 ";
                    sql += " where OutputVolumeNew='" + 生产批号 + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "罩退小标签打印次数更新");
                    break;
                case "退火小标签":
                    sql = "update  Bus_Bus_FireOutputOutput set  PrintTimes =PrintTimes+1 ";
                    sql += " where OutputVolumeNew='" + 生产批号 + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "退火小标签打印次数更新");
                    break;
                case "硅钢小标签":
                    sql = "update  Bus_SiOutput set  PrintTimes =PrintTimes+1 ";
                    sql += " where OutputVolumeNew='" + 生产批号 + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "硅钢小标签打印次数更新");
                    break;
            }
            ba.Quit();
            this.Close();
        }

        private void uiButton取消_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void Form酸洗小标签_Load(object sender, EventArgs e)
        {
            this.uiTextBox卷号.Text = 生产批号;
            this.uiTextBox品名.Text = 品名;
            this.uiTextBox存货编号.Text = 存货编号;
            this.uiTextBox执行标准.Text = 执行标准;
            this.uiTextBox材质.Text = 钢号;
            this.uiTextBox规格.Text = 规格;
            this.uiTextBox质量等级.Text = 等级;
            this.uiTextBox重量.Text = 净重;
            this.uiTextBox长度.Text = 长度;
            this.uiTextBox表面处理.Text = 表面处理;
            this.uiTextBox表面状态.Text = 表面状态;
            this.uiTextBox产线.Text = 产线名称;
            this.uiTextBox颜色.Text = 颜色;
            this.uiTextBox班组.Text = 班组;
            this.uiTextBox锌层.Text = 锌层;
            this.uiTextBox客户.Text = 客户;
            this.uiTextBox包装.Text = 包装;

            加载仓库();
            this.uiComboBox仓库编号.SelectedValue = 仓库;
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            string 仓库 = uiComboBox仓库编号.SelectedValue?.ToString();
            string 锌层 = uiTextBox锌层.Text;
            ////string 包装形式 = uiComboBox包装.Text;
            ////pub.全局包装 = uiComboBox包装.Text;
            ////pub.全局仓库 = uiComboBox仓库编号.SelectedValue.ToString();
            //if (string.IsNullOrEmpty(仓库))
            //{
            //    MessageBox.Show("请选择仓库");
            //}
            ////if (string.IsNullOrEmpty(包装形式))
            ////{
            ////    MessageBox.Show("请选择包装形式");
            ////}

            string sql;
            sql = "delete Bus_LablePrint where 生产批号='" + 生产批号 + "'";
            pub.ExecuteSql(pub.ConnectionString, sql, "小标签打印前清理");
            sql = "insert into Bus_LablePrint(guid, 来源种类,来源产线,工厂编号, 生产批号,  品名, 钢号, 条码, 长度, 规格, 等级, 表面状态,  ";
            sql += " 表面处理, 净重, 备注, 生产日期,  操作ip, 操作人员, 操作时间 ,仓库,锌层,包装形式,班组,颜色,客户) ";
            sql += " values(newid(),'" + 来源种类 + "','"+产线名称+"','" + 工厂编号 + "','" + 生产批号 + "',";
            sql += " '" + 品名 + "','" + 钢号 + "','" + 生产批号 + "','" + 长度 + "','" + 规格 + "','" + 等级 + "','" + 表面状态 + "',";
            sql += " '" + 表面处理 + "','" + 净重 + "','" + 执行标准 + "','" + 生产日期 + "','" + pub.getMac() + "',";
            sql +=" '" + pub.sys_user.UserTrueName + "',getdate(),'" + 仓库 + "','" + 锌层 + "','" + 包装 + "','"+ 班组 + "','"+ 颜色 +"','"+ 客户 +"')";
            if (pub.ExecuteSql(pub.ConnectionString, sql, "小标签打印塞入") > 0)
            {
                switch (来源种类)
                {
                    case "酸洗小标签":
                        sql = "update  Bus_PicklingOutput set PrintTimes =PrintTimes+1 ";
                        sql += " where OutputVolumeNew='" + 生产批号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "酸洗小标签打印次数更新");
                        break;
                    case "轧硬小标签":
                        sql = "update  Bus_HardOutput set  PrintTimes =PrintTimes+1 ";
                        sql += " where OutputVolumeNew='" + 生产批号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "轧硬小标签打印次数更新");
                        break;
                    case "镀锌小标签":
                        sql = "update  Bus_ZincOutput set  PrintTimes =PrintTimes+1 ";
                        sql += " where OutputVolumeNew='" + 生产批号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "镀锌小标签打印次数更新");
                        break;
                    case "彩涂小标签":
                        sql = "update  Bus_PaintOutput set  PrintTimes =PrintTimes+1 ";
                        sql += " where OutputVolumeNew='" + 生产批号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "彩涂小标签打印次数更新");
                        break;
                    case "罩退小标签":
                        sql = "update  Bus_CoverFireOutput set  PrintTimes =PrintTimes+1 ";
                        sql += " where OutputVolumeNew='" + 生产批号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "罩退小标签打印次数更新");
                        break;
                    case "退火小标签":
                        sql = "update  Bus_Bus_FireOutputOutput set  PrintTimes =PrintTimes+1 ";
                        sql += " where OutputVolumeNew='" + 生产批号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "退火小标签打印次数更新");
                        break;
                    case "硅钢小标签":
                        sql = "update  Bus_SiOutput set  PrintTimes =PrintTimes+1 ";
                        sql += " where OutputVolumeNew='" + 生产批号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "硅钢小标签打印次数更新");
                        break;
                }
            }

            this.Close();
        }

        private void 加载仓库()
        {
                pub.ListWareHouse(this.uiComboBox仓库编号,pub.全局工厂guid);
        }
    }
}
